package ru.st.selenium;

import org.testng.annotations.*;
import static org.junit.Assert.*;
import ru.st.selenium.model.User;
import ru.st.selenium.model.Film;


public class SearchFilm_test extends ru.st.selenium.pages.TestBase{

	
	@BeforeMethod
	public void mayBeLogout() {
		if (app.getUserHelper().isNotLoggedIn()) {
			return;
		}
	    app.getUserHelper().logout();
	}
	
	@Test
	public void testSearchFilmTrue() throws Exception {
		User user = new User().setLogin("admin").setPassword("admin");
		Film film = new Film().setTitle("Test_"+System.currentTimeMillis()).setYear("2013");
		 
		app.getUserHelper().loginAs(user);
		assertTrue(app.getUserHelper().isLoggedInAs(user));
		 /////////////////////// create new movie
		app.getNavigationHelper().gotoMyCollectionPage();
		app.getNavigationHelper().gotoUserAddFilmPage();
		app.getFilmHelper().create(film);
		app.getNavigationHelper().gotoMyCollectionPage();
		 ////////////////////// search created movie
		app.getFilmHelper().searchFilm(film.getTitle());
		app.getFilmHelper().filmIsFounded(film.getTitle());

		app.getFilmHelper().delete(film);
	}
	
	@Test
	public void testSearchFilmFalse() throws Exception {
		User user = new User().setLogin("admin").setPassword("admin");
		Film film = new Film().setTitle("wrong name").setYear("2013");
		 
		app.getUserHelper().loginAs(user);
		assertTrue(app.getUserHelper().isLoggedInAs(user));
		  
		app.getNavigationHelper().gotoMyCollectionPage();
		app.getFilmHelper().searchFilm(film.getTitle());
		app.getFilmHelper().filmNotFound();
	}
}
